//
//  ZYCProtalCalendarCell.m
//  ZDSC
//
//  Created by ZDTX on 2021/7/18.
//

#import "ZYCProtalCalendarCell.h"
#import "ZYCNewBulletinModel.h"
#import "ZYCNoticeCalendarModel.h"

@interface ZYCProtalCalendarCell ()


@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *line;
@property (nonatomic, strong) UILabel *timeLabel;
@property (nonatomic, strong) UILabel *nameLabel;
@property (nonatomic, strong) UIButton *statusButton;

@end
@implementation ZYCProtalCalendarCell

- (void)setModel:(ZYCNewBulletinModel *)model{
    _model = model;
    _titleLabel.text = model.title;
    _timeLabel.text = model.createTime;
    _nameLabel.text = model.publisher;
}

- (void)setCModel:(ZYCNoticeCalendarModel *)cModel{
    _cModel = cModel;
    _titleLabel.text = cModel.title;
    _timeLabel.text = cModel.createTime;
    _nameLabel.text = cModel.publisher;
    [_statusButton setTitle:cModel.readStatus forState:UIControlStateNormal];
    
    NSInteger readFlag = [cModel.readFlag integerValue];
    [_statusButton setTitle:cModel.readStatus forState:UIControlStateNormal];
    if (readFlag == 0) {// 读
        [_statusButton setTitleColor:HEX_RGB(@"#E6350A") forState:UIControlStateNormal];
        [_statusButton buttonWithCornerRadius:7.5f borderWidth:0.5 borderColor:HEX_RGB(@"#E6350A")];
        _statusButton.enabled = YES;
    }else{//已读
        [_statusButton setTitleColor:HEX_RGB(@"#ADADAD") forState:UIControlStateNormal];
        [_statusButton buttonWithCornerRadius:7.5f borderWidth:0.5 borderColor:HEX_RGB(@"#ADADAD")];
        _statusButton.enabled = NO;
    }
    

}


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self.contentView addSubview:self.titleLabel];
        [self.contentView addSubview:self.line];
        [self.contentView addSubview:self.timeLabel];
        [self.contentView addSubview:self.nameLabel];
        [self.contentView addSubview:self.statusButton];
    
        [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView).offset(19.0f);
            make.right.equalTo(self.contentView).offset(-19.0f);
            make.top.equalTo(self.contentView).offset(20.0f);
        }];
        [self.line mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView).offset(19.0f);
            make.right.equalTo(self.contentView).offset(-19.0f);
            make.top.equalTo(self.titleLabel.mas_bottom).offset(17.0f);
            make.height.mas_equalTo(1.0f);
        }];
        
        [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView).offset(19.0f);
//            make.top.equalTo(self.line.mas_bottom).offset(19.0f);
            make.bottom.equalTo(self.contentView).offset(-21.0f);
        }];
        
        [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.timeLabel.mas_right).offset(54.0f);
            make.centerY.equalTo(self.timeLabel);
        }];
        
        [self.statusButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.contentView).offset(-19.0f);
            make.centerY.equalTo(self.timeLabel);
            make.size.mas_equalTo(CGSizeMake(55.0f, 25.0f));
        }];
    }
    return self;
}


- (UILabel *)titleLabel {
    if (!_titleLabel) {
        _titleLabel = [UILabel LabelWithFont:kSystemBoldFont(17) titleColor:HEX_RGB(kTitleThemeColor) textAlignment:ZZTextAlignmentLeft];
    }
    return _titleLabel;
}

- (UILabel *)timeLabel {
    if (!_timeLabel) {
        _timeLabel = [UILabel LabelWithFont:kCustomFont(@"PingFangSC-Light", 14) titleColor:HEX_RGB(@"#888888") textAlignment:ZZTextAlignmentLeft];
    }
    return _timeLabel;
}

- (UILabel *)nameLabel {
    if (!_nameLabel) {
        _nameLabel = [UILabel LabelWithFont:kCustomFont(@"PingFangSC-Light", 14) titleColor:HEX_RGB(@"#888888") textAlignment:ZZTextAlignmentLeft];
    }
    return _nameLabel;
}

- (UIButton *)statusButton {
    if (!_statusButton) {
        _statusButton = [[UIButton alloc] init];
        _statusButton.titleLabel.font = kCustomFont(@"PingFangSC-Light", 14.0f);
        _statusButton.titleLabel.textAlignment = NSTextAlignmentCenter;
        [_statusButton addTarget:self action:@selector(clickReadAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _statusButton;
}

- (UILabel *)line {
    if (!_line) {
        _line = [[UILabel alloc] init];
        _line.backgroundColor = HEX_RGB(@"#EAEAEA");
    }
    return _line;
}

- (void)clickReadAction:(UIButton *)sender{
    if (self.clickReadBlock) {
        self.clickReadBlock(self);
    }
}


@end
